<template>
  <el-card class="box-card-component" style="margin-top:10px">
    <div slot="header" class="box-card-header">
      <el-tooltip class="item" effect="dark" content="修改背景图" placement="top-start">
        <el-upload
          class="avatar-uploader"
          action="/api/upload/back_image"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload">
        <img :src="imageUrl+'?rondom='+ Math.ceil(Math.random()*5)">
        </el-upload>
      </el-tooltip>
    </div>
    <div style="position:relative;">
      <pan-thumb :image="avatar" class="panThumb" />
      <mallki class-name="mallki-text" text="翼来电云平台" />
      <div style="padding-top:25px;" class="progress-item">
        <el-link type="success" v-html="name" style="margin-left: 15px"></el-link>
     </div>
<!--      <div class="progress-item">-->
<!--        <span>JavaScript</span>-->
<!--        <el-progress :percentage="18" />-->
<!--      </div>-->
<!--      <div class="progress-item">-->
<!--        <span>CSS</span>-->
<!--        <el-progress :percentage="12" />-->
<!--      </div>-->
<!--      <div class="progress-item">-->
<!--        <span>ESLint</span>-->
<!--        <el-progress :percentage="100" status="success" />-->
<!--      </div>-->
    </div>
  </el-card>
</template>

<script>
import { mapGetters } from 'vuex'
import PanThumb from '@/components/PanThumb'
import Mallki from '@/components/TextHoverEffect/Mallki'
import { getBack } from '@/api/main'
export default {
  components: { PanThumb, Mallki },

  filters: {
    statusFilter(status) {
      const statusMap = {
        success: 'success',
        pending: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      statisticsData: {
        article_count: 1024,
        pageviews_count: 1024
      },
      imageUrl:'/upload/image/login.jpeg'
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'avatar',
      'roles'
    ])
  },
  created(){
    this.getBack()
  },
  methods: {
    getBack(){
      getBack().then(response=>{
        this.imageUrl =response.data.url
      })
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = res.data.url
      this.$notify.success({
        title: '成功',
        message: '背景图修改成功，若未发生改变请清理缓存',
        type: 'success',
        duration: 2000
      })
      // this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      // const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 5;

      // if (!isJPG) {
      //   this.$message.error('图片只能是 JPG 格式!');
      // }
      if (!isLt2M) {
        this.$message.error('图片大小不能超过 5MB!');
      }
      return isLt2M;
    }
  }
}
</script>

<style lang="scss" >
.box-card-component{
  .el-card__header {
    padding: 0px!important;
  }
}
</style>
<style lang="scss" scoped>
.box-card-component {
  .box-card-header {
    position: relative;
    height: 210px;
    img {
      width: 100%;
      height: 100%;
      transition: all 0.2s linear;
      &:hover {
        transform: scale(1.1, 1.1);
        filter: contrast(130%);
      }
    }
  }
  .mallki-text {
    position: absolute;
    top: 0px;
    right: 0px;
    font-size: 20px;
    font-weight: bold;
  }
  .panThumb {
    z-index: 100;
    height: 70px!important;
    width: 70px!important;
    position: absolute!important;
    top: -45px;
    left: 0px;
    border: 5px solid #ffffff;
    background-color: #fff;
    margin: auto;
    box-shadow: none!important;
    ::v-deep .pan-info {
      box-shadow: none!important;
    }
  }
  .progress-item {
    margin-bottom: 10px;
    font-size: 14px;
  }
  @media only screen and (max-width: 1510px){
    .mallki-text{
      display: none;
    }
  }
}
</style>
